package cn.itcast.order.web;

import cn.itcast.feign.pojo.Order;
import cn.itcast.order.config.UserPatternProperties;
import cn.itcast.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
//@RefreshScope // 热更新
@Slf4j
public class OrderController {

    private final UserPatternProperties userPatternProperties;
    private final OrderService orderService;

    public OrderController(UserPatternProperties userPatternProperties, OrderService orderService) {
        this.userPatternProperties = userPatternProperties;
        this.orderService = orderService;
    }


    @GetMapping("/{orderId}")
    public Order queryOrderByUserId(@PathVariable("orderId") Long orderId, @RequestHeader(name = "username",required = false) String username) {
        return orderService.queryOrderById(orderId);
    }

    @GetMapping("/getUsername")
    public String getUsername() {
        return userPatternProperties.getName();
    }

}
